package io.cici.cc.mybatis.lite.type;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public final class TypeHandlerRegistry {
    public static final ShortTypeHandler shortTypeHandler = new ShortTypeHandler();
    public static final IntegerTypeHandler integerTypeHandler = new IntegerTypeHandler();
    public static final LongTypeHandler longTypeHandler = new LongTypeHandler();
    public static final StringTypeHandler stringTypeHandler = new StringTypeHandler();
    public static final ClobTypeHandler clobTypeHandler = new ClobTypeHandler();
    public static final BigDecimalTypeHandler bigDecimalTypeHandler = new BigDecimalTypeHandler();
    public static final BigIntegerTypeHandler bigIntegerTypeHandler = new BigIntegerTypeHandler();
    public static final DateTypeHandler dateTypeHandler = new DateTypeHandler();
    //
    public static final String SHORT = "short";
    public static final String INT = "int";
    public static final String LONG = "long";
    public static final String BIGDECIMAL = "bigdecimal";
    public static final String BIGINTEGER = "biginteger";
    public static final String STRING = "string";
    public static final String CLOB = "clob";
    public static final String DATE = "date";
    private final static Map<String, TypeHandler<?>> typeToTypeHandlerMap = new ConcurrentHashMap<>();

    static {
        typeToTypeHandlerMap.put(SHORT, shortTypeHandler);
        typeToTypeHandlerMap.put(INT, integerTypeHandler);
        typeToTypeHandlerMap.put(LONG, longTypeHandler);
        typeToTypeHandlerMap.put(BIGDECIMAL, bigDecimalTypeHandler);
        typeToTypeHandlerMap.put(BIGINTEGER, bigIntegerTypeHandler);
        typeToTypeHandlerMap.put(STRING, stringTypeHandler);
        typeToTypeHandlerMap.put(CLOB, clobTypeHandler);
        typeToTypeHandlerMap.put(DATE, dateTypeHandler);
    }

    public static boolean hasTypeHandler(String javaType) {
        return typeToTypeHandlerMap.containsKey(javaType);
    }

    public static TypeHandler getTypeHandler(String type) {
        return typeToTypeHandlerMap.get(type);
    }


}
